<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台登录</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
    <style>
        .body-bg {
            background: #01AAED;
        }
        .body-pop {
            background: #fff;
        }
        .layui-container {
            /* 绝对居中 */
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            width: 480px;
            height: 380px;
            background: #fff;
            padding: 20px;
            border-radius: 4px;
            box-shadow: 5px 5px 20px #333;
        }
        .layui-pop {
            padding: 20px;
        }
    </style>
</head>

<body class="{{$pop ? 'body-pop' : 'body-bg'}}">
    <div class="{{$pop ? 'layui-pop' : 'layui-container'}}">
        <form class="layui-form" method="post" action="">
            @csrf
            @if (!$pop)
            <div class="layui-form-item">
                <h1>通用后台管理系统</h1>
            </div>
            <hr>
            @endif
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="text" name="username" value="admin" required lay-verify="required" placeholder="请输入用户名" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" value="123456" required lay-verify="required" placeholder="请输入密码" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                    <input type="text" name="captcha" required lay-verify="required" placeholder="验证码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-word-aux"><img src="/admins/account/vericode" style="height:40px;cursor:pointer;" onclick="this.src='/admins/account/vericode?'+Math.random()"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">记住我</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="remember" title="记住密码" checked lay-skin="primary">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="login">登录</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <script>
        //login
        layui.use(['form'], function() {
            var form = layui.form,
                $ = layui.jquery;

            //监听提交
            form.on('submit(login)', function(data) {
                $.post('/admins/account/dologin', data.field, function(res) {
                    if (res.code) {
                        layer.alert(res.msg, {
                            icon: 2
                        });
                        return;
                    }
                    layer.alert(res.msg, {
                        icon: 1
                    });
                    setTimeout(function() {
                        let parentIndex = parent.layer.getFrameIndex(window.name);
                        if (typeof parentIndex !== "undefined") {
                            parent.layer.close(parentIndex);
                            parent.window.location.reload();
                        } else {
                            window.location.href = '/admins/home/index'
                        }
                    }, 1000);
                }, 'json');
                return false;
            });
        });
    </script>
</body>

</html>